import paho.mqtt.client as mqtt
#https://www.cnblogs.com/saryli/p/9820532.html
#brew services stop mosquitto
#brew services start mosquitto

def on_connect(client, userdata, flags, rc):
    print("Connected with result code: " + str(rc))

def on_message(client, userdata, msg):
    print("receive msg:",msg.topic,msg.payload)




sub_client=mqtt.Client()

sub_client.on_connect=on_connect
sub_client.on_message=on_message
sub_client.username_pw_set("admin","158246")
sub_client.connect('192.168.1.16',1884,600)

sub_client.subscribe('/root/topic/mask', qos=0)
sub_client.loop_forever() # 保持连接


